home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / ps2epsi < prev    next >
Encoding:
Text File  |  2006-11-28  |  2.0 KB  |  89 lines

  1. #!/bin/sh
  2. # $Id: ps2epsi 6505 2006-01-27 21:58:27Z giles $
  3.  
  4. # This definition is changed on install to match the
  5. # executable name set in the makefile
  6. GS_EXECUTABLE=gs
  7.  
  8. # try to create a temporary file securely
  9. tmpdir=/tmp/ps2epsi.$$
  10. (umask 077 && mkdir $tmpdir)
  11. if ! test -d $tmpdir; then
  12.     echo "failed: could not create temporary file"
  13.     exit 1
  14. fi
  15. tmpfile=$tmpdir/ps2epsi$$
  16.  
  17. export outfile
  18.  
  19. if [ $# -lt 1 -o $# -gt 2 ]; then
  20.     echo "Usage: `basename $0` file.ps [file.epsi]" 1>&2
  21.     exit 1
  22. fi
  23.  
  24. infile=$1;
  25.  
  26. if [ $# -eq 1 ]
  27. then
  28.     case "${infile}" in
  29.       *.ps)        base=`basename "${infile}" .ps` ;;
  30.       *.cps)    base=`basename "${infile}" .cps` ;;
  31.       *.eps)    base=`basename "${infile}" .eps` ;;
  32.       *.epsf)    base=`basename "${infile}" .epsf` ;;
  33.       *)        base=`basename "${infile}"` ;;
  34.     esac
  35.     outfile=${base}.epsi
  36. else
  37.     outfile=$2
  38. fi
  39.  
  40. ls -l "${infile}" |
  41. awk 'F==1    {
  42.         cd="%%CreationDate: " $6 " " $7 " " $8;
  43.         t="%%Title: " $9;
  44.         f="%%For:" U " " $3;
  45.         c="%%Creator: Ghostscript ps2epsi from " $9;
  46.         next;
  47.         }
  48.     /^%!/    {next;}
  49.     /^%%Title:/    {t=$0; next;}
  50.     /^%%Creator:/    {c=$0; next;}
  51.     /^%%CreationDate:/    {cd=$0; next;}
  52.     /^%%For:/    {f=$0; next;}
  53.     !/^%/    {
  54.         print "/ps2edict 30 dict def";
  55.         print "ps2edict begin";
  56.         print "/epsititle (" t "\\n) def";
  57.         print "/epsicreator (" c "\\n) def";
  58.         print "/epsicrdt (" cd "\\n) def";
  59.         print "/epsifor (" f "\\n) def";
  60.         print "end";
  61.         exit(0);
  62.         }
  63.     ' U="$USERNAME$LOGNAME"  F=1 - F=2 "${infile}" >$tmpfile
  64.  
  65. $GS_EXECUTABLE -q -dNOPAUSE -dSAFER -dDELAYSAFER -r72 -sDEVICE=bit -sOutputFile=/dev/null $tmpfile ps2epsi.ps $tmpfile <"${infile}" 1>&2
  66. rm -f $tmpfile
  67. rm -rf $tmpdir
  68.  
  69. (
  70. cat << BEGINEPS
  71. save countdictstack mark newpath /showpage {} def /setpagedevice {pop} def
  72. %%EndProlog
  73. %%Page 1 1
  74. BEGINEPS
  75.  
  76. cat "${infile}" |
  77. sed -e '/^%%BeginPreview:/,/^%%EndPreview[^!-~]*$/d' -e '/^%!PS-Adobe/d'\
  78.     -e '/^%%[A-Za-z][A-Za-z]*[^!-~]*$/d' -e '/^%%[A-Za-z][A-Za-z]*: /d'
  79.  
  80. cat << ENDEPS
  81. %%Trailer
  82. cleartomark countdictstack exch sub { end } repeat restore
  83. %%EOF
  84. ENDEPS
  85.  
  86. ) >> "${outfile}"
  87.  
  88. exit 0
  89.